package com.hclc.util.collection;

import org.springframework.util.CollectionUtils;

import java.util.HashSet;
import java.util.Set;

/**
 * @ClassName CollectionUtil
 * @Author: yurj
 * @Mail：1638234804@qq.com
 * @Date: Create in 17:17 2019-11-16
 * @version: 1.0
 */
public class CollectionUtil {

    /**
     * 求set交集
     * @param set1
	 * @param set2
     * @return java.lang.String
     * @author yurj
     * @mail 1638234804@qq.com
     * @version 1.0
     * @date 2019-11-16 17:19
     */

    public static Boolean retainAll(Set<String> set1 , Set<String> set2){
        if(CollectionUtils.isEmpty(set1) || CollectionUtils.isEmpty(set2)){
            return false;
        }
        //交集
        set1.retainAll(set2);
        return set1.size() > 0 ? true : false;
    }

    public static void main(String[] args) {
        Set<String> set1 = new HashSet<>();
        Set<String> set2 = new HashSet<>();

        set1.add("a");
        set1.add("b");
        set1.add("c");

        set2.add("c");
        set2.add("d");
        set2.add("e");

        //交集
        set1.retainAll(set2);
        System.out.println(set1);
        System.out.println(set1.size());
    }
}
